package cn.fuck;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public class TestReducetions {
    public static void main(String[] args) throws IOException {
        String wordString = new String(Files.readAllBytes(Paths.get("" +
                "D:\\IDEA\\Code22\\src\\cn\\fuck\\word.txt")));
        List<String> words = Arrays.asList(wordString.split("\\W+"));
        // max
        Optional<String> largest = words.stream().max(String::compareToIgnoreCase);
        System.out.println("largest: " + largest.orElse(""));  // value为空则返回""

        // findFirst
        Optional<String> firstStartWithY = words.stream().filter(s -> s.startsWith("A")).findFirst();
        System.out.println("firstStartWithY: " + firstStartWithY.orElse(""));
    }
}
